package com.xckj.cycling.utils

import android.graphics.BitmapFactory
import android.graphics.Rect
import android.graphics.drawable.Drawable
import android.graphics.drawable.NinePatchDrawable
import android.view.View
import android.widget.ImageView
import com.bumptech.glide.Glide
import com.bumptech.glide.load.resource.bitmap.CircleCrop
import com.xckj.cycling.R
import com.xckj.cycling.context.AppContext

fun ImageView.loadHead(url: String?) {
    Glide.with(this).load(url).placeholder(R.mipmap.ic_default_img).transform(CircleCrop())
        .into(this)
}

fun getCardBg(): Drawable {
    val rect = Rect()
    val bitmap =
        BitmapFactory.decodeResource(
            AppContext.globalContext().resources,
            R.mipmap.img_mine_function_bg
        )
    val chunk = BitmapUtils.makeNinePatchChunk(bitmap)
    return NinePatchDrawable(AppContext.globalContext().resources, bitmap, chunk, rect, "card_bg")
}

fun View.setCardBg() {
    background = getCardBg()
}